from Common.Base import Base, open_browser

"""
封装页面表现层:制作页面元素定位器
Page类继承Base类
"""
Register_url = "http://localhost:8080/ecshop/user.php?act=register"


class RegisterPage(Base):
    """制做定位器,封装注册页面表现层"""
    username_loc = ("id", "username")  # 注册用户名
    email_loc = ("id", "email")  # 注册页面邮箱
    password_loc = ("name", "password")  # 注册页面密码
    conform_password_loc = ("id", "conform_password")  # 注册页面确认密码
    qq_number_loc = ("name", "extend_field2")  # 注册页面QQ账号
    office_phone_loc = ("name", "extend_field3")  # 注册页面办公电话
    home_phone_loc = ("name", "extend_field4")  # 注册页面家庭电话
    mobile_phone_loc = ("name", "extend_field5")  # 注册页面手机
    password_question_select_loc = ("name", "sel_question")  # 定位注册页面密码提示问题
    password_question_answer = ("name", "passwd_answer")  # 注册页面密码问题答案
    user_agreement_loc = ("link text", "用户协议")  # 用户协议
    agreement_checkbox_loc = ("name", "agreement")  # 注册页面用户协议选择框
    submit_loc = ("class name", "us_Submit_reg")  # 立即注册
    have_account_number_loc = ("link text", "我已有账号，我要登录")  # 注册页面我已有账号，我要登录
    forget_password_loc = ("link text", "您忘记密码了吗？")  # 注册页面您忘记密码了吗？
    homepage_loc = ("link text", "首页")  # 首页按钮
    result_loc = ("class name", "f4_b")  # 注册结果

    def input_username(self, username):
        """
        用户名输入
        :param username: username
        :return:
        """
        self.send_keys(text=username, locator=self.username_loc)

    def input_email(self, email):
        """
        邮箱输入
        :param email: email
        :return:
        """
        self.send_keys(text=email, locator=self.email_loc)

    def input_password(self, password):
        """
        密码输入
        :param password:password
        :return:
        """
        self.send_keys(text=password, locator=self.password_loc)

    def input_conform_password(self, password):
        """
        密码确认输入
        :param password: password
        :return:
        """
        self.send_keys(text=password, locator=self.conform_password_loc)

    def input_qq_number(self, qq):
        """
        qq号输入
        :param qq: qq
        :return:
        """
        self.send_keys(text=qq, locator=self.qq_number_loc)

    def input_office_phone(self, office_phone):
        """
        办公电话号码输入
        :param office: office_number
        :return:
        """
        self.send_keys(text=office_phone, locator=self.office_phone_loc)

    def input_home_phone(self, home_phone):
        """
        家庭电话输入
        :param home_phone: home_phone
        :return:
        """
        self.send_keys(text=home_phone,locator=self.home_phone_loc)
    def input_mobile_phone(self,mobile_phone):
       """
       手机号码输入
       :param mobile_phone: mobile_phone
       :return:
       """
       self.send_keys(text=mobile_phone,locator=self.mobile_phone_loc)
    def select_password_question(self,option):
        """
        密码提示问题选择
        :return:
        """
        self.select_drop_down_menu(index=option,locator=self.password_question_select_loc)
    def answer_password_question(self,answer):
        """
        密码答案输入
        :param answer: answer
        :return:
        """
        self.send_keys(text=answer,locator=self.password_question_answer)
    def click_user_agreement(self):
        """
        用户协议浏览
        :return:
        """
        self.click(locator=self.user_agreement_loc)
    def check_agreement_checkbox(self):
        """
        用户协议选择框勾选
        :return:
        """
        self.click(locator=self.agreement_checkbox_loc)
    def register_submit(self):
        """
        立即注册按钮
        :return:
        """
        self.click(locator=self.submit_loc)
    def click_have_account_number(self):
        """
        点击注册页面我已有账号,我也登录
        :return:
        """
        self.click(locator=self.have_account_number_loc)
    def click_forget_password(self):
        """
        点击注册页面您忘记密码了吗?
        :return:
        """
        self.click(locator=self.forget_password_loc)

    def register_homepage(self):
        """
        首页链接
        :return:
        """
        self.click(locator=self.homepage_loc)
    def is_register_success(self, username):
        """
        判断登录是否成功
        :return:
        """
        return self.is_text_in_element(text=username, locator=self.result_loc)
if __name__ == '__main__':
    import time
    driver = open_browser("firefox")
    page = RegisterPage(driver)
    page.open_url(Register_url)
    # page.input_username("大乔")
    # page.input_email("1072441902@qq.com")
    # page.input_password("123456")
    # page.input_conform_password("123456")
    # page.input_qq_number("1072441902")
    # page.input_office_phone("028-888888")
    # page.input_home_phone("028-666666")
    # page.input_mobile_phone("18211111111")
    page.select_password_question(1)
    # page.answer_password_question("1234")
    # page.check_agreement_checkbox()
    # page.register_submit()
    # page.click_user_agreement()
    # page.click_have_account_number()
    # page.click_forget_password()

    time.sleep(3)
    page.close_browser()


